<?php
class event_data extends data 
{
	public function __construct()
	{
		parent::__construct();
		
	}
	
	public function getEventListProgrammed() 
	{	
		$this->query("SELECT r.eventid as id,  r.eventname, i.istancename, r.startdate, r.enddate, r.duedate FROM event as r, istance as i WHERE r.istanceid = i.istanceid  and r.duedate > ".time()." ORDER BY r.startdate DESC");
		if($this->num_rows())
			return $this->fetch_all_row();
		else 
			return null;
	}
	
	public function getEventListExpired() {
		$this->query("SELECT r.eventid as id,  r.eventname, i.istancename, r.startdate, r.enddate, r.duedate FROM event as r, istance as i WHERE r.istanceid = i.istanceid and r.duedate < ".time()." ORDER BY r.startdate DESC");
		if($this->num_rows())
			return $this->fetch_all_row();
		else 
			return null;
		
	}
	
	public function getEvent() {
		$this->query("SELECT * FROM event WHERE eventid='{$_POST['eventid']}'");
			return $this->fetch_array();
		
	}
	
	public function setEvent($eventname, $istanceid, $raidid,  $comment, $startdate, $enddate, $duedate, $onlymain, $onlyprimaryspec) {
		if(isset($_POST['eventid']) and $_POST['eventid'] != null )
		{
			if(!$this->query("UPDATE event SET istanceid = '$istanceid', raidid= $raidid, eventname = '$eventname', startdate = '$startdate', enddate = '$enddate',  duedate = '$duedate', comment = '$comment',  onlymain = '$onlymain', onlyprimaryspec = '$onlyprimaryspec'  WHERE eventid = '{$_POST['eventid']}'"))
				return $this->error;
		}
		else 
		{
			if(!$this->query("INSERT INTO event SET istanceid = '$istanceid', raidid= $raidid, eventname = '$eventname', startdate = '$startdate', enddate = '$enddate',  duedate = '$duedate', comment = '$comment',  onlymain = '$onlymain', onlyprimaryspec = '$onlyprimaryspec'"))
				return $this->error;
		}
	}
	
	public function deleteEvent() {
		if(!$this->query("DELETE FROM event WHERE eventid ='{$_POST['eventid']}'"))
			return $this->error;
	}
}
?>